<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>会员登录</title>
    <!-- Bootstrap -->
    <link href="../js/bootstrap/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>


<!--登录-->
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <form class="form-horizontal" >

                <div class="form-group">
                    <label  class="col-sm-2 control-label">会员名:</label>
                    <div class="col-sm-4">
                        <input type="text" name="memberName" class="form-control" id="memberName" placeholder="请输入会员名">
                    </div>
                    <div id="memberNameTip"></div>
                </div>

                <div class="form-group">
                    <label  class="col-sm-2 control-label">密码:</label>
                    <div class="col-sm-4">
                        <input type="password" name="password" class="form-control" id="password" placeholder="请输入密码">
                    </div>
                    <div id="passwordTip"></div>
                </div>

                <div style="text-align: center;">
                    <button type="button" class="btn btn-primary" onclick="login()">登录</button>
                    <button type="reset" class="btn btn-default">重置</button>
                    <a style="margin-left: 50px" href="retrievePas.html">修改密码(前提输入邮箱验证码)</a>
                    <button type="reset" class="btn btn-default" onclick="javascript:location.href='forgetPassword.html'">忘记密码(随机向邮箱发送验证码)</button>

                </div>
            </form>
        </div>
    </div>
</div>


<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script src="../js/jquery-3.3.1.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="../js/bootstrap/js/bootstrap.min.js"></script>
<!--引入封装好的cookie-->
<script src="../js/jquery.cookie.min.js"></script>

<script src="../js/common.js"></script>
</body>

<script>

    /**
     * 登录
     */
    function login(){
       let memberName=$("#memberName").val().trim();
       let password=$("#password").val().trim();
        $.post({
            data: {
                    "memberName":memberName,
                    "password":password
                  },
            url:"http://localhost:9000/members/api/members/login",
           /* beforeSend:function (xhr){
                let v_token=$.cookie("fh-token");
                xhr.setRequestHeader("x-auth",v_token);
            },*/
            success:function(res){
                if(res.code==200){
                    //获取后台返回的token
                    let memberData=res.data
                    //将服务端响应给客户端的信息存入会话cookie
                    $.cookie("token",memberData)
                    location.href="index.html";
                }else if(res.code==5116){
                    alert(res.msg);
                    $.cookie("memberData",JSON.stringify(res.data));
                    location.href="sendActivationMemberMail.html"
                }
            },
            error:function(){
                alert("发送请求异常");
            }
        })
    }
</script>

</html>
